package com.example.capsule_netty.netty;

import com.example.capsule_netty.bean.MessageBean;
import com.google.gson.Gson;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

import java.io.File;
import java.io.RandomAccessFile;

/**
 * @Author: zhuzhiming
 * @Date: 2022/4/30 11:39
 */
public class NettyFileHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {

        MessageBean messageBean = new Gson().fromJson((String) msg, MessageBean.class);
        if (messageBean.getMsgType() == 1) {
          //  byte[] bytes = messageBean.getBytes();
            RandomAccessFile randomAccessFile = new RandomAccessFile(new File("data/" + messageBean.getFileName()), "rw");
            //randomAccessFile.write(bytes);
        }
    }
}
